package com.example.musicproject_b.Controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.b_pojo.Musiccategory;
import com.example.common.utils.Resultb;
import com.example.service.BMusicCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/B_admin/musiccategory")
public class BMusicCategoryController {

    @Autowired
    private BMusicCategoryService bMusicCategoryService;

    /**
     * @return
     * @param @param null
     * @author znk
     * @date 2024/9/14 16:20
     * 文章分类列表（不包含逻辑删除）
     */
    @RequestMapping("/alllist")
    public Resultb alllist(int pageNum, int pageSize) {
        Page<Musiccategory> alllist = bMusicCategoryService.alllist(pageNum, pageSize);
        if (alllist.getTotal() > 0){
            return Resultb.success(alllist);
        }else {
            return Resultb.error();
        }
    }

    /**
     * @return
     * @param @param null
     * @author znk
     * @date 2024/9/14 16:21
     * 文章分类列表（包含逻辑删除）
     */
    @RequestMapping("/hasdelectlist")
    public Resultb hasdelectlist(int pageNum, int pageSize) {
        Page<Musiccategory> hasdelectlist = bMusicCategoryService.hasdelectlist(pageNum, pageSize);
        if (hasdelectlist.getTotal() > 0){
            return Resultb.success(hasdelectlist);
        }else {
            return Resultb.error();
        }
    }

    /**
     * @return
     * @param @param null
     * @author znk
     * @date 2024/9/14 16:24
     * 根据id查询分类信息(包括逻辑删除)
     */
    @RequestMapping("/getcategoryById")
    public Resultb getcategoryById(Long id) {
        Musiccategory categoryById = bMusicCategoryService.getcategoryById(id);
        if (categoryById != null){
            return Resultb.success(categoryById);
        }else {
            return Resultb.error();
        }
    }

    /**
     * @return
     * @param @param null
     * @author znk
     * @date 2024/9/14 16:25
     * 根据分类名称查询分类信息(不包括逻辑删除)
     */
    @RequestMapping("/getcategoryByName")
    public Resultb getcategoryByName(String categoryName) {
        List<Musiccategory> categoryList = bMusicCategoryService.getcategoryByName(categoryName);
        if (categoryList.size() > 0){
            return Resultb.success(categoryList);
        }else {
            return Resultb.error();
        }
    }


    /**
     * @return
     * @param @param null
     * @author znk
     * @date 2024/9/14 16:21
     * 增加文章分类
     */
    @RequestMapping("/insertcategory")
    public Resultb insertcategory(@RequestBody Musiccategory musiccategory) {
        boolean insert = bMusicCategoryService.insertcategory(musiccategory);
        if (insert){
            return Resultb.success();
        }else {
            return Resultb.error();
        }
    }

    /**
     * @return
     * @param @param null
     * @author znk
     * @date 2024/9/14 16:23
     * 修改文章分类(包含逻辑删除)
     */
    @RequestMapping("/updatecategory")
    public Resultb updatecategory(@RequestBody Musiccategory musiccategory) {
        boolean update = bMusicCategoryService.updateById(musiccategory);
        if (update){
            return Resultb.success();
        }else {
            return Resultb.error();
        }
    }

    /**
     * @return
     * @param @param null
     * @author znk
     * @date 2024/9/14 16:24
     * 启用和禁用分类
     */
    @RequestMapping("/startandstopcategory")
    public Resultb startandstopcategory(Long id) {
        boolean startandstopcategory = bMusicCategoryService.startandstopcategory(id);
        if (startandstopcategory){
            return Resultb.success();
        }else {
            return Resultb.error();
        }
    }

    /**
     * @return
     * @param @param null
     * @author znk
     * @date 2024/9/14 16:24
     * 彻底删除分类
     */
    @RequestMapping("/deletecategory")
    public Resultb deletecategory(Long id) {
        boolean delete = bMusicCategoryService.removeById(id);
        if (delete){
            return Resultb.success();
        }else {
            return Resultb.error();
        }
    }

}
